package com.hxkj.controller.analyze;

import com.hxkj.domain.po.FreeMarker;
import com.hxkj.service.analyze.CreatedFreeMakerSerivice;
import com.platform.common.domain.exception.CustomMessageException;
import com.platform.common.domain.result.ResultMessageStruct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.Callable;

/**
 * 一键生成模板
 * <p>
 * Created by yaosy on 2018年7月10日19:44:20
 */
@RestController
@RequestMapping("/createFreeMaker")
public class CreateFreeMakerController {

    @Autowired
    private CreatedFreeMakerSerivice createdFreeMakerSerivice;


    /****
     * 一鍵生成静态模板
     *
     * @return Exception
     * ***/
    @RequestMapping(value = "/create")
    public Callable<ResultMessageStruct> create(@ModelAttribute FreeMarker freeMarker) {
        return () -> {
            ResultMessageStruct result = new ResultMessageStruct();
            try {
                createdFreeMakerSerivice.createSiteAll(freeMarker);
                result.setMessage("成功");
                result.setCode(200);
            }catch (CustomMessageException e){
                result.setMessage(e.getMessage());
                result.setCode(e.getCode());
            }
            return  result;
        };
    }
}
